package com.manager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.manager.entity.dao.Campus;
import com.manager.entity.dao.SubCampus;
import com.manager.entity.dto.SdkManagerInfoDto;
import com.manager.service.ICampusService;
import com.manager.service.IManagerService;
import com.manager.service.ISubCampusService;
import com.security.anno.IgnoreController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 供外部服务调用获取管理员信息的接口
 *
 * @author 大忽悠
 * @create 2023/2/15 12:45
 */
@Validated
@RestController
@RequestMapping("/sdk")
@RequiredArgsConstructor
@Api("SDK请求")
@IgnoreController
public class SdkController {
    private final IManagerService iManagerService;
    private final ISubCampusService iSubCampusService;
    private final ICampusService iCampusService;

    @ApiOperation("返回管理员ID,如果不存在当前管理员,返回null")
    @GetMapping("/getIdByName")
    public SdkManagerInfoDto loadByName(@RequestParam("name") String userRealName) {
        return iManagerService.loadByName(userRealName);
    }

    @ApiOperation("查询当前主校区下是否存在对应的分校区")
    @GetMapping("/existSubCampusUnderCampus")
    public Boolean existSubCampusUnderCampus(@RequestParam("campusId")Integer campusId,@RequestParam("subCampusId")Integer subCampusId){
        return iSubCampusService.existSubCampusUnderCampus(campusId,subCampusId);
    }

    @GetMapping("/existSubCampus")
    public Boolean existSubCampus(@RequestParam("campusId")Integer campusId){
        return iSubCampusService.count(new QueryWrapper<SubCampus>().eq("id", campusId))!=0;
    }

    @GetMapping("/existCampus")
    public Boolean existCampus(@RequestParam("campusId")Integer campusId){
        return iCampusService.count(new QueryWrapper<Campus>().eq("id", campusId))!=0;
    }
}
